import json

import requests
requests.packages.urllib3.disable_warnings()

# 获取签到状态
def getSignStatus():
    url = 'https://app-api.9917.cn/v3/user/task/getData'
    data = {
        "member_id": memberId,
    }
    data = baseRequest(url, headers, data)
    print(data)
    if data['status']['succeed'] == 1:
        data = data['data']
        userInfo = data['user_info']
        integral = userInfo['integral']
        userName = userInfo['username']
        # 今日签到信息
        signInfo = data['sign_info']
        # 今天是否签到
        isSignResult = signInfo['today_issign']
        signStatus = '已签到' if isSignResult else '未签到'
        print(f'当前账户为：{userName},积分为：{integral}，签到状态：{signStatus}')
        if isSignResult is False:
            print('开始签到')
        else:
            signStart()
    else:
        print(data)


# 获取签到状态
def signStart():
    url = 'https://app-api.9917.cn/v3/user/task/sign'
    data = {
        "member_id": memberId,
        "username": "17603017302",
    }
    data = baseRequest(url, headers, data)
    if data['status']['succeed'] == 1:
        data = data['data']
        todayGet = data['today_sign_get_integral']
        print(f'签到成功，获得：{todayGet}')
    else:
        print(data)

# 发起请求
def baseRequest(url , headers , data):
    result = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
    content = result.content.decode('utf8')
    data = json.loads(content)
    return data

if __name__ == '__main__':

    headers = {
        # ':authority': 'app-api.9917.cn',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Sec-Fetch-Site': 'same-site',
        'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
        'Accept-Encoding': 'gzip, deflate, br',
        'Sec-Fetch-Mode': 'cors',
        'Content-Type': 'application/json;charset=utf-8',
        'token': '5fdde561fd0193c8a16ccb7eeec6293b',
        'Origin': 'https://sys.9917.cn',
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 TcTravel/10.6.8 tctype/wk',
        'Referer': 'https://sys.9917.cn/',
        'Sec-Fetch-Dest': 'empty',
    }
    memberId = '5063233'
    # 先签到，再来完成任务
    print('-----------------幻梦游戏盒-开始签到流程-----------------')
    getSignStatus()